
import requests


def get_binance_server_time():
    url = "https://api.binance.com/api/v3/time"
    response = requests.get(url)
    if response.status_code == 200:
        server_time = response.json()['serverTime']
        return server_time
    else:
        raise Exception("无法获取币安服务器时间")



def check_kyc_status(api_key, api_secret):
    """检查账户KYC状态"""
    import requests
    import hmac
    import hashlib
    import time

    base_url = "https://api.binance.com"
    endpoint = "/sapi/v1/account/status"
    # timestamp = int(time.time() * 1000)
    timestamp = get_binance_server_time()
    params = f"timestamp={timestamp}&recvWindow=5000"
    signature = hmac.new(
        api_secret.encode('utf-8'),
        params.encode('utf-8'),
        hashlib.sha256
    ).hexdigest()

    url = f"{base_url}{endpoint}?{params}&signature={signature}"
    headers = {"X-MBX-APIKEY": api_key}

    try:
        response = requests.get(url, headers=headers, timeout=10)
        data = response.json()
        print(f"账户状态: {data}")
        return data
    except Exception as e:
        print(f"检查失败: {e}")
        return None


API_KEY = "oMlYVBgANplqH7XilK0rzJ47r7p1R3MWoywVNBYOGvj5UHYXebQnxZjX9kLpdd5V"
API_SECRET = "8587vRjV45QsPPXhlrn3vcBdUwQJFA6HIBqfaVbJO7UqhhqTcVrQCR4GEO6w4OtN"
check_kyc_status(API_KEY, API_SECRET)